#include "ScreenManager.h"
#include "Singleton.h"
#include "EventHandler.h"
#include "EventPoller.h"
#include "Text.h"
#include "Ray.h"
#include "CSCamera.h"

#include <d3d11.h>
#include <dxgi.h>
#include <dinput.h>
#include <D3DX10math.h>

class CameraManager : public Uncopyable, public EventHandler
{
	CameraManager();
	friend class Singleton<CameraManager>;
public:
	~CameraManager();
	void Draw();
	void Update();

	CSCamera& GetCamera();
	
	const D3DXVECTOR3& GetCameraTarget() const {return m_target;}
	const D3DXVECTOR3& GetCameraPos() const;
	const D3DXVECTOR3& GetLookAt() const;

	virtual void OnKeyDownEvent(const WPARAM& event);
	virtual void OnKeyUpEvent(const WPARAM& event);
	virtual void OnMouseMotionEvent(const LPARAM& event);
	virtual void OnMouseButtonDownEvent(const MSG& event);
	virtual void OnMouseButtonUpEvent(const MSG& event);
	virtual void OnMouseWheelEvent(const WPARAM& event);

	void AddEventHandler();
	void RemoveEventHandler();
	
	
private:
	void SetBirdsEyeViewMatrix();
	void LimitCameraMovements();

	void UpdateMain();

private:
	
	CSCamera m_camera;
	bool m_spaceBarDown;
	bool m_ctrlDown;

	//unsigned char* m_keyboardState;
	DIMOUSESTATE m_mouseState;

	D3DXVECTOR3 m_pos;
	//D3DXVECTOR3 m_camMazePos;
	D3DXVECTOR3 m_target;
	D3DXVECTOR3 m_up;

	D3DXVECTOR3 m_miniMapPos;

	D3DXMATRIX m_view;
	D3DXMATRIX m_reflectedView;

	float m_xRot, m_yRot, m_zRot;
	D3DXVECTOR3 m_radi;

	D3DXVECTOR3 m_vel;
	float m_angleH;
	float m_angleV;
	float m_rotAngle;

	bool m_mouseLeftDown;
	float m_zoom;
	float m_zoomVel;

	bool m_takingKeyboardInput;

	float m_moveAcc;
	float m_moveVel;
	bool m_wKeyDown;
	bool m_aKeyDown;
	bool m_sKeyDown;
	bool m_dKeyDown;
	bool m_zKeyDown;
	bool m_xKeyDown;
	bool m_pgUpKeyDown;
	bool m_pgDownKeyDown;

	bool m_lMouseButtonDown;
	bool m_rMouseButtonDown;
	float m_currentMouseX;
	float m_currentMouseY;
	float m_mouseX;
	float m_mouseY;
	float m_mouseWheelDelta;
};

typedef Singleton<CameraManager> TheCameraManager;